package tagImage;
import java.io.File;
import java.util.*;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
 
/**
  * @since 11/12/2012 
  * @author lyos2210
  * the aim of this file is to search directory or a file
  *  with a special extensions.
  */
public class RechercheFichier {
	
	private JFileChooser myFileChooser;
	private ArrayList<String> FileList;
	
	public RechercheFichier() {
		myFileChooser = new JFileChooser();
		myFileChooser.setCurrentDirectory(new File("."));
		myFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
		try {
			int value = myFileChooser.showOpenDialog(null);
			if (value == JFileChooser.APPROVE_OPTION) {
				File SelectedFile = myFileChooser.getSelectedFile();
				String Filename = SelectedFile.getPath();
				FileList = new ArrayList<String>();
				if (SelectedFile.isDirectory()) {
					String[] myFile = SelectedFile.list();
					for (int i = 0; i < myFile.length; i++) {
						if (myFile[i].endsWith(".png") == true
								|| myFile[i].endsWith(".jpg") == true
								|| myFile[i].endsWith(".jpeg") == true) {
							FileList.add(Filename + "/" + myFile[i]);
						}
					}
				} else
					FileList.add(Filename);
			} else
				JOptionPane.showMessageDialog(null,
						"User did not choose a file.");
		} catch (Exception e) {
			JOptionPane.showMessageDialog(null, e.getMessage(), "Error",
					JOptionPane.ERROR_MESSAGE);
		}
	}
	
	//getter and setter
	public ArrayList<String> getFileList() {
		return FileList;
	}
	
	public void setFileList(ArrayList<String> fileList) {
		FileList = fileList;
	}
	
/**	
	public void RechercheFichierFile(final String extension) {
		JFileChooser chooser = new JFileChooser();
		chooser.setCurrentDirectory(new File("."));
		chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
			public boolean accept(File f) {
				return f.getName().toLowerCase().endsWith("." + extension)
						|| f.isDirectory();
			}

			public String getDescription() {
				String ext = extension.toUpperCase().toString();
				return (ext + "Images");
			}
		});
		int r = chooser.showOpenDialog(new JFrame());
		if (r == JFileChooser.APPROVE_OPTION) {
			String name = chooser.getSelectedFile().getName();
			System.out.println(name);
		}
	}
**/
	
//	public static void main(String[] args) {
//		new RechercheFichier();
//	}

}
